import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.0
Rectangle {
    width: 800; height: 800
    RowLayout {
        Button {
            id: pos1
            width:100;
            height: 16;
            text: "pos1"
            tooltip :"扣车";
            onClicked:{
                room1.updateDot(200, 200)
            }
        }

        Button {
            id: pos2
            width:100;
            height: 16;
            text: "pos2"
            tooltip :"扣车";
            onClicked:{
                room1.updateDot(400, 200)
            }
        }
    }

    Rectangle {
        id: room1
        width: 600; height: 600
        y: 20
        color: "lightblue"

        Rectangle {
            id: obj1
            width: 20
            height: 20
            radius: width
            color: "red"
            x: 100
            y: 100
        }

        function updateDot(x, y)
        {
            obj1.x = x
            obj1.y = y
        }

        MouseArea {//?????
            id: rootItemMouseArea
            enabled: true//rootItem.visible
            anchors.fill: parent;
            drag.target: room1;
            drag.filterChildren: true;
            acceptedButtons: Qt.LeftButton | Qt.RightButton| Qt.MidButton;
            onClicked: {
                if(mouse.button == Qt.MidButton){
                    room1.scale = 1;
                    room1.x = 0;
                    room1.y = 0;
                    }
            }
            onWheel: {
                if(wheel.angleDelta.y < 0){
                    if(room1.scale <= 0.1){
                        room1.scale = 0.1;
                    }
                    else{
                        room1.scale = room1.scale - 0.1;
                        if(room1.scale > 1){
                            room1.x = room1.x * 0.95;
                            room1.y = room1.y * 0.95;
                        }
                        else{
                            room1.x = room1.x * 0.9;
                            room1.y = room1.y * 0.9;
                        }
                    }
                }
                else{
                    room1.scale = room1.scale + 0.1;
                    if(room1.scale < 1.5){
                        room1.x = room1.x * 1.1;
                        room1.y = room1.y * 1.1;
                    }else{
                        room1.x = room1.x * 1.05;
                        room1.y = room1.y * 1.05;
                    }

                }
            }
        }
    }
}